﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Castle.Core.Internal;
using Coldairarrow.Business.Goods;
using Coldairarrow.Entity.Goods;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;

namespace Coldairarrow.Api.Controllers.backstage
{
    [Route("/backstage/[controller]/[action]")]
    public class BKS_GoodsTypeController : BaseApiController
    {
        #region DI

        public BKS_GoodsTypeController(IBTB_GoodsTypeBusiness bTB_GoodsTypeBus)
        {
            _bTB_GoodsTypeBus = bTB_GoodsTypeBus;
        }

        IBTB_GoodsTypeBusiness _bTB_GoodsTypeBus { get; }

        #endregion
        /// <summary>
        /// 查询所有分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public List<BTB_GoodsType> All()
        {
            return _bTB_GoodsTypeBus.All();
        }
        /// <summary>
        /// 查询二级分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public List<BTB_GoodsType> AllBackstage()
        {
            return _bTB_GoodsTypeBus.AllBackstage();
        }
        /// <summary>
        /// 查询一级分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public List<BTB_GoodsType> AllOneBackstage()
        {
            return _bTB_GoodsTypeBus.AllOneBackstage();
        }
        /// <summary>
        /// 查看指定商品类型
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task< BTB_GoodsType> GetTheData(IdInputDTO input)
        {
            return await _bTB_GoodsTypeBus.GetTheDataAsync(input.id);
        }
        /// <summary>
        /// 添加或修改商品类型
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BTB_GoodsType data)
        {
            if (data.id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _bTB_GoodsTypeBus.AddDataAsync(data);
            }
            else
            {
                await _bTB_GoodsTypeBus.UpdateDataAsync(data);
            }
        }
        /// <summary>
        /// 删除指定商品类型
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bTB_GoodsTypeBus.DeleteDataAsync(ids);
        }
    }
}
